package com.aabte.spring.annotation.config;

import com.aabte.spring.beans.Person;
import com.aabte.spring.service.BookService;
import com.aabte.spring.typefilter.MyTypeFilter;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.annotation.*;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Controller;
import org.w3c.dom.Element;

/**
 * {@link ComponentScan}注解原理：
 * {@link AbstractBeanDefinitionParser#parse(Element, ParserContext)}
 * {@link AnnotationConfigUtils#registerAnnotationConfigProcessors}
 * {@link ClassPathScanningCandidateComponentProvider#registerDefaultFilters()}
 * {@link ClassPathBeanDefinitionScanner}
 * {@link ClassPathBeanDefinitionScanner#doScan(String...)}
 * {@link PathMatchingResourcePatternResolver#findPathMatchingResources}获取匹配的资源
 *
 * @author Daniel
 */
@Configuration
@ComponentScan(value = "com.aabte.spring")
@ComponentScan(value = "com.aabte.spring",
        excludeFilters = {
                // 排除Controller注解的扫描
                @ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class}),
                // 排除具体的类型
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {BookService.class}),
                // 使用自定义过滤器
                @ComponentScan.Filter(type = FilterType.CUSTOM, value = {MyTypeFilter.class})
        })
// @ComponentScan(value = "com.aabte.spring",
//         // 关闭默认过滤器（excludeFilter）
//         useDefaultFilters = false,
//         includeFilters = {
//                 // 只扫描Service注解
//                 @ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Service.class})
//         })
// @ComponentScans(value = {
//         @ComponentScan(value = "com.aabte.spring",
//                 excludeFilters = {
//                         // 排除Controller注解的扫描
//                         @ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Controller.class})
//                 }),
//         @ComponentScan(value = "com.aabte.spring",
//                 // 关闭默认过滤器（excludeFilter）
//                 useDefaultFilters = false,
//                 includeFilters = {
//                         // 只扫描Service注解
//                         @ComponentScan.Filter(type = FilterType.ANNOTATION, value = {Service.class})
//                 })
// })
public class ComponentScanConfig {

    @Bean(name = "jack")
    public Person person() {
        return Person.builder()
                .name("jack")
                .age(19)
                .build();
    }

}
